import {http} from '../../utils/http'
Page({
  data:{
    // 左侧数据
    left:[],
    // 右侧数据
    right:[],
    // 全部数据
    list:[],
    activeKey:0,
    img:[
      {img:'../../image/22/1.jpg'},
      {img:'../../image/22/2.jpg'},
      {img:'../../image/22/3.jpg'},
      {img:'../../image/22/4.jpg'}
    ]
  },
  async getlist(){
    let cui = await http({url:'shop/goods/category/all'}).catch(err=>err)
    
    let list = cui.data.data
    
    let left = []
    let right = []
    list.forEach(item=>{
      if(item.level==1){
        left.push(item)
      }else{
        right.push(item)
      }
    })
    console.log(left)
    this.setData({
      right,
      left,
      list
    })
  },
  one(e){
    console.log(e)
    let name = e.currentTarget.dataset.name
     let cui = this.data.right.filter(item=>{
      return item.type.includes(name)
    })
    console.log(cui)
    this.setData({
      list:cui
    })
  },
  all(){
    this.setData({
      list:this.data.right
    })
  },
  onLoad(){
    this.getlist()
  }
})
// 所有分类的接口
// https://api.it120.cc/small4/shop/goods/category/all
